package Demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Collectors;

public class Test2 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "a,12", "b,13", "c,14");

        Student[] arr = list.stream()
                .map(new Function<String, Student>() {
                    @Override
                    public Student apply(String s) {
                        String name = s.split(",")[0];
                        int age = Integer.parseInt(s.split(",")[1]);
                        return new Student(name, age);
                    }
                })
                .collect(Collectors.toList())
                .toArray(new IntFunction<Student[]>() {
                    @Override
                    public Student[] apply(int value) {
                        return new Student[value];
                    }
                });

        System.out.println(Arrays.toString(arr));
    }
}
